/**
 * 
 */
package org.teremail.provider;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

import com.google.inject.Provider;

public class FutureProvider<T> implements Provider<T> {

    final FutureTask<T> future;
    
    public FutureProvider(Callable<T> callable) {
        future = new FutureTask<T>(callable);
    }
    
    public T get() {
        future.run();
        try {
            return future.get();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }        
}